package JDK8Time;

import org.junit.Test;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Month;

public class LocalDateTimeApITest {

    @Test
    public void test01(){
        //获取本地日期时间
        LocalDateTime currentTime= LocalDateTime.now();
        System.out.println("当前时间"+currentTime);

        //获取本地日期
        LocalDate date1=currentTime.toLocalDate();
        System.out.println("当前日期"+date1);

        //获取年月日
        Month month=currentTime.getMonth();
        int day=currentTime.getDayOfMonth();
        int year=currentTime.getYear();
        System.out.println(year+"年"+month+"月"+day+"日");

        //修改时间
        LocalDateTime date2=currentTime.withDayOfMonth(20).withYear(2020);
        System.out.println(date2);

        // 12 december 2014
        LocalDate date3 = LocalDate.of(2014, Month.DECEMBER, 12);
        System.out.println("date3: " + date3);

        // 22 小时 15 分钟
        LocalTime date4 = LocalTime.of(22, 15);
        System.out.println("date4: " + date4);

        // 解析字符串
        LocalDate date5 = LocalDate.parse("2015-03-25");
        System.out.println("date5: " + date5);
        Month month1=date5.getMonth();
        System.out.println(month1.getValue());
    }

}
